<%@ page language="java" contentType="text/html; charset=UTF-8"
	pageEncoding="UTF-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>学生信息列表页</title>
<!-- 下载并引入jquery easyUI -->
<link rel="stylesheet" type="text/css"
	href="${pageContext.request.contextPath}/jquery-easyui-1.8.8/themes/gray/easyui.css">
<link rel="stylesheet" type="text/css"
	href="${pageContext.request.contextPath}/jquery-easyui-1.8.8/themes/icon.css">
<link rel="stylesheet" type="text/css"
	href="${pageContext.request.contextPath}/jquery-easyui-1.8.8/themes/color.css">
<script type="text/javascript"
	src="${pageContext.request.contextPath}/jquery-easyui-1.8.8/jquery.min.js"></script>
<script type="text/javascript"
	src="${pageContext.request.contextPath}/jquery-easyui-1.8.8/jquery.easyui.min.js"></script>


</head>
<body>
	<table id="student_dg" title="学生信息列表" class="easyui-datagrid"
		style="width: 1150px; height: 480px"
		url="${param.request.contextPath}/student/stuInfo/stuinfo"
		toolbar="#student_toolbar" pagination="true" rownumbers="true"
		fitColumns="true" singleSelect="true">
		<thead>
			<tr>
				<th field="cb" checkbox="true" align="center"></th>
				<th field="stuId" width="50">学号</th>
				<th field="stuName" width="50">姓名</th>
				<th field="sex" formatter="sexFormatter" width="50">性别</th>
				<th field="birthdate" width="50">出生日期</th>
				<th field="place" width="50">籍贯</th>
				<th field="address" width="50">家庭住址</th>
				
				<th field="custName" formatter="custodianFormatter" width="50">监护人</th>
				<th field="claId" formatter="classFormatter" width="50">班级编号</th>
				<th field="dormId" formatter="dormFormatter" width="50">宿舍编号</th>
				<th field="cardId" formatter="spendsFormatter" width="50">校园卡号</th>
			</tr>
		</thead>
	</table>

	<!-- 工具条组件 -->
	<div id="student_toolbar">
		<a href="javascript:void(0)" class="easyui-linkbutton"
			iconCls="icon-edit" plain="true" onclick="editStuinfo()">修改密码</a>
	</div>

	<!-- 修改表单  start -->
	<div id="student_dlg" class="easyui-dialog"
		style="width: 400px; height: 280px; padding: 10px 20px" closed="true"
		buttons="#student_dlg-buttons">
		<div class="ftitle">学生信息管理</div>
		<form id="student_fm" enctype="multipart/form-data" method="post">
			<div class="fitem">
				<label>密码:</label> <input name="password" class="easyui-validatebox"
					required="true">
			</div>

		</form>
	</div>
	<div id="student_dlg-buttons">
		<a href="#" class="easyui-linkbutton" iconCls="icon-ok"
			onclick="saveStuinfo()">保存</a> <a href="#" class="easyui-linkbutton"
			iconCls="icon-cancel"
			onclick="javascript:$('#student_dlg').dialog('close')">取消</a>
	</div>

	<!-- 新增和修改表单 end -->

	<script type="text/javascript">
		function sexFormatter(value, row, index) {
			if (value == 1) {
				return '男';
			}
			return '女';
		}

		function custodianFormatter(value, row, index) {
			if (row.custodian == null) {
				return null;

			}
			return row.custodian.custName;
		}

		function classFormatter(value, row, index) {
			if (row.classs == null) {
				return null;

			}
			return row.classs.claId;
		}

		function dormFormatter(value, row, index) {
			if (row.dorm == null) {
				return null;

			}
			return row.dorm.dormId;
		}

		function spendsFormatter(value, row, index) {
			if (row.spends == null) {
				return null;

			}
			return row.spends.cardId;
		}

		// 修改
		function editStuinfo() {
			//$('#student_fm').form('clear');
			var row = $('#student_dg').datagrid('getSelected');
			if (row) {
				$('#student_dlg').dialog('open').dialog('setTitle', '修改学生信息');
				$('#student_fm').form('load', row);
				url = '${pageContext.request.contextPath}/student/edit?stuId='
						+ row.stuId;

			}
		}

		function saveStuinfo() {
			$('#student_fm').form('submit', {
				url : url,
				onSubmit : function() {
					return $(this).form('validate');
				},
				success : function(result) {
					var result = eval('(' + result + ')');
					if (!result.success) {
						$.messager.show({
							title : 'Error',
							msg : result.errorMsg
						});
					} else {
						$.messager.show({
							title : 'Info',
							msg : result.errorMsg
						});
					}

					$('#student_dlg').dialog('close'); // close the dialog
					$('#student_dg').datagrid('reload'); // reload the user data
				}
			});
		}
	</script>
</body>
</html>